Linux 安装自定义 systemctl 服务

| 2020-05-26 11:13:58

实现对服务的更新和启动

/usr/lib/systemd/system//etc/systemd/system/ 建立文件 blog.service 写入以下内容

[Unit]
Description = println.fun
Documentation = http://fun.println
After = network.target remote-fs.target nss-lookup.target

[Service]
ExecStart = /usr/bin/java -jar /opt/blog/current/target/println-0.1.jar --spring.profiles.active=qa
ExecReload = /bin/kill -s HUP $MAINPID
ExecStop = /bin/kill -s QUIT $MAINPID
PrivateTmp = true

[Install]
WantedBy = multi-user.target

具体含义:

命令指南

使服务生效:

systemctl enable blog

启动服务

systemctl start blog

重启服务

systemctl restart blog

关闭服务

systemctl stop blog

查看服务状态

systemctl status blog

加入开机启动

systemctl enable blog

显示服务状态是否 Active

systemctl is-active blog

从开机启动中删除

systemctl disable blog

显示所有已启动服务

systemctl list-units --type=service

刷新服务

systemctl daemon-reload